home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Utilities / PalmLink / src / PL_Init.c < prev    next >
C/C++ Source or Header  |  2000-05-05  |  4KB  |  128 lines

  1. /**
  2.  * PalmLink -- Connect 3Com Palm with Amiga
  3.  *
  4.  * Library initialization, C part
  5.  *
  6.  * (C) 1998-2000 Richard Körber <rkoerber@gmx.de>
  7.  *
  8.  *------------------------------------------------------------------
  9.  *
  10.  * This program is free software; you can redistribute it and/or modify
  11.  * it under the terms of the GNU General Public License as published by
  12.  * the Free Software Foundation; either version 2 of the License, or
  13.  * any later version.
  14.  *
  15.  * This program is distributed in the hope that it will be useful,
  16.  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17.  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  18.  * GNU General Public License for more details.
  19.  *
  20.  * You should have received a copy of the GNU General Public License
  21.  * along with this program; if not, write to the Free Software
  22.  * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  23.  *
  24.  * You must not use this source code to gain profit of any kind!
  25.  */
  26.  
  27. #include "palmlink_glob.h"
  28.  
  29. /*----------------------------------------------------------------
  30. ** GLOBAL VARIABLES
  31. */
  32. struct DOSBase       *DOSBase;
  33. struct Library       *UtilityBase;
  34. struct Library       *SysBase;
  35. struct Library       *RexxSysBase;
  36. struct Library       *PalmlinkBase;
  37.  
  38. struct Global         global;
  39.  
  40.  
  41. /*----------------------------------------------------------------
  42. ** InitGlobal   Initializes the global structure
  43. */
  44. static int InitGlobal(void)
  45. {
  46.   for(;;)
  47.   {
  48.     if(!(global.slptrash = AllocMem(1024,MEMF_PUBLIC))) break;
  49.  
  50.     NewList(&global.rexxHandles);
  51.     InitSemaphore(&global.rexxHandleSemaphore);
  52.     global.rexxHandleOK = TRUE;
  53.  
  54.     return 1;                   // Okay
  55.   }
  56.   return 0;                     // Failure
  57. }
  58.  
  59. /*----------------------------------------------------------------
  60. ** ExitGlobal   Frees global structure
  61. */
  62. static void ExitGlobal(void)
  63. {
  64.   struct RexxHandle *thisNode, *nextNode;
  65.  
  66.   if(global.slptrash) FreeMem(global.slptrash,1024);
  67.  
  68.   if(global.rexxHandleOK)
  69.   {
  70.     global.rexxHandleOK = FALSE;
  71.     ObtainSemaphore(&global.rexxHandleSemaphore);
  72.     for                                                     // Clean up the handle list
  73.     (
  74.       thisNode = (struct RexxHandle *)global.rexxHandles.lh_Head;
  75.       nextNode = (struct RexxHandle *)thisNode->rh_node.ln_Succ;
  76.       thisNode = nextNode
  77.     )
  78.     {
  79.       Remove((struct Node *)thisNode),
  80.       FreeVec(thisNode);
  81.     }
  82.   }
  83.  
  84.   return;
  85. }
  86.  
  87.  
  88. /*----------------------------------------------------------------
  89. ** LibExit      Finishes Library
  90. */
  91. __saveds __asm void LibExit(void)
  92. {
  93.   ExitGlobal();
  94.   if(DOSBase)       CloseLibrary((struct Library *)DOSBase);
  95.   if(UtilityBase)   CloseLibrary(                  UtilityBase);
  96.   if(RexxSysBase)   CloseLibrary(                  RexxSysBase);
  97. }
  98.  
  99.  
  100. /*----------------------------------------------------------------
  101. ** LibInit      Initializes the Library
  102. */
  103. __saveds __asm struct Library *LibInit
  104. (
  105.   register __a0 struct Library *exec,
  106.   register __a1 struct Library *base
  107. )
  108. {
  109.   SysBase      = exec;
  110.   PalmlinkBase = base;
  111.  
  112.   for(;;)
  113.   {
  114.     if(!(DOSBase       = (struct DOSBase *)      OpenLibrary("dos.library"        ,36L))) break;
  115.     if(!(UtilityBase   =                         OpenLibrary("utility.library"    ,36L))) break;
  116.     if(!(RexxSysBase   =                         OpenLibrary("rexxsyslib.library" ,36L))) break;
  117.  
  118.     if(!(InitGlobal()))   break;
  119.  
  120.     return(base);         // Everything worked fine
  121.   }
  122.   LibExit();
  123.   return(0);
  124. }
  125.  
  126. /****************************************************************/
  127.  
  128.